import { View } from "@tarojs/components";
import Taro from "@tarojs/taro";
import { Current } from "@tarojs/runtime";
import { useState, useEffect, useCallback } from "react";

//公共组件
import LgNavCustomBar from '../../components/navCustomBar'

import { useSelector, useDispatch } from "react-redux";
import LgSelectModalEdu from "../LGcomponents/LgSelectModalEdu";
import getInfo from '../utils/getInfo'
import { getStorage } from '../../components/utils'
import MyUtils from '../components/personal/utils'
import "./index.scss";
// import {
//   setSelectUsers,
//   setSelectDayteacher,
//   setCopyUser,
// } from "@/store/slice";

function App() {
  // const dispatch = useDispatch();
  // const commonData = useSelector((state: any) => state.commonData);

  // const { token, sysInfo, selectUser, selectDayteacher, copyUser, sysId } = commonData;
  // console.log(sysInfo)
  // console.log(commonData)


  const onConfirm = useCallback((data) => {
    console.log(data)
    MyUtils.setStorage("showChoObjArr", data)
    MyUtils.setStorage("chooseObject", data)
    let str = ''
    if (data.length > 0) {
      data.forEach(i => {
        if(i.hasOwnProperty('structureVoList')) {
          console.log('选了组')
          if (!str.includes('部分部门')) {
            if (str.length === 0) {
              str += '部分部门'
            } else {
              str += ',部分部门'
            }
          }
        } else {
          console.log('没选组')
          if (!str.includes('个人')) {
            if (str.length === 0) {
              str += '个人'
            } else {
              str += ',个人'
            }
          }
        }
      })
    }
    MyUtils.setStorage("typeObjStr", str)
    Taro.navigateBack({});
  }, []);

  useEffect(() => {
    console.log(MyUtils.getStorage("toChooseObject"))
  }, []);

  return (
    <View className="new_select_modal">
         <LgNavCustomBar
              mainTitle={'选择对象'}
              needMainIcon={process.env.TARO_ENV === 'weapp' ? false : true}
              needBackIcon={true}
              isTitlePositionLeft={true}
              mainTitleBold={false}
            ></LgNavCustomBar>
      <View className="new_select_body">
        <LgSelectModalEdu
          backData='all'
          token={getInfo.getToken()}
          officeUrl={MyUtils.getStorage("userInfo").baseUrl + 'edu-office-platform' || ""}
          selectUserList={MyUtils.getStorage("toChooseObject").receivers}
          recentList={MyUtils.getStorage("toChooseObject").receivers}
          onConfirm={onConfirm}
        ></LgSelectModalEdu>
      </View>
    </View>
  );
}
export default App;
